<?php
	include('header.php');
	
	if (isset($_POST['search_request'])) { // Traitement de la recherche
		
		if (!isset($_POST['advanced'])) $_POST['advanced']= array();

		if (isset($_POST['age_all'])) {
			$_POST['age_from']= '';
			$_POST['age_to']= '';
		}
		
		$resRequest = RequestDB::getRequestIdsWithCriteria($_POST['sel_periode'], $_POST['sel_ville'], $_POST['sel_loyer'], $_POST['sel_promotion'], $_POST['sel_nb_colloc'], $_POST['age_from'], $_POST['age_to'], $_POST['advanced']);
		$resFullRequest= false;
		
		if ($resRequest && (mysql_num_rows($resRequest) > 0)) { // Requete OK et au moins une annonce
			$idRequests;
			while ($row= mysql_fetch_array($resRequest)) {
				$idRequests[]= $row['idAdvert'];
			}
			$resFullRequest = RequestDB::getRequestsFromIds($idRequests);
		}
		
		$nbAnnonces = 0;
		if($resFullRequest) $nbAnnonces = mysql_num_rows($resFullRequest);
		
		include(TPL_DIR . 'resultat_demandes.html');
	
	} else { // Affichage du formulaire
		include(TPL_DIR . 'demandes.html');
		
	}
	
	include('footer.php');

?>